home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / MPW Script Tips 1.1.1 / Sample Scripts / SS < prev    next >
Encoding:
Text File  |  1991-08-16  |  2.2 KB  |  54 lines  |  [TEXT/MPS ]

  1. #-----------------------------------------------------------------------------------------------------------------------------------------------------
  2. # SS (Search and Set)
  3. # MPW Shell Script
  4. # Written by C.K. Haun
  5. # Modified by Gina Cherry • August 16,1991
  6. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  7. #
  8. # Usage:
  9. #        SS [fileToFind]
  10. #
  11. # Function:
  12. #     Search for a file and set directory to the directory containing the file.
  13. #        If a file is not specified on the command line, a dialogue will prompt the user for a file name.
  14. #-----------------------------------------------------------------------------------------------------------------------------------------------------
  15.  
  16. # Don't exit on error.
  17.     Set Exit 0                                            
  18.  
  19. # If a parameter was given, set fileToFind to the parameter.
  20.     If {#} == 1                                            
  21.         Set fileToFind "{1}"                            
  22.         
  23. # Otherwise, display a dialogue asking for file name.  Exit script if Cancel is chosen.
  24.     Else                                                     
  25.         Set fileToFind "`Request "Program to find:" || Echo`"      
  26.         Exit If "{fileToFind}" == ""                         
  27.     End
  28.  
  29.     Echo "Finding file ∂"{fileToFind}∂"" >> "{Worksheet}"
  30.  
  31. # Search for fileToFind, starting at the {MPW} directory.  
  32. # Set the dirIn to the full pathname of fileToFind.
  33.     Set dirIn "`whereis -s "{MPW}" -c "{fileToFind}"`"         
  34.                                                         
  35. # If fileToFind is not found, print error message and exit script.                                                        
  36.     If "{dirIn}" == ""
  37.         Echo "### {0}: Couldn't find file ∂"{fileToFind}∂"" >> Dev:StdErr
  38.         Exit 1
  39.     End
  40.  
  41.  
  42. # Pick out the directory name from the file's full path name.
  43. # The Evaluate statement is used for its side effect of allowing the shell access to ® variables.
  44. # The statement picks out the name of the directory containing fileToFind from the regular 
  45. # expression, and assigns the directory name to ®1.  ®1 can then be used as a shell variable.
  46. #
  47. # Note: dirIn will be a string enclosed in single quotes if the file path name includes any special 
  48. #    characters, such as spaces.  Therefore, the regular expression to which dirIn is compared must
  49. #    begin with the characters ∂'*, which means "0 or more single quotations marks".
  50.     (Evaluate "{dirIn}" =~ /∂'*(([¬:]*:)+)®1[¬:]*/ ) ∑ Dev:Null 
  51.                                                             
  52.  
  53.     Echo "Setting directory to ∂"{®1}∂"" >> "{Worksheet}"        
  54.     SetDirectory "{®1}"